﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Configuration;

namespace SingleUserMall.ModelMessage
{
    public class WeiXinHelper
    {
        /// <summary>
        /// 微信开发者 AppId
        /// </summary>
        public static string AppId = WebConfigurationManager.AppSettings["wxpay_h5_appid"];

        /// <summary>
        /// 微信开发者 Secret
        /// </summary>
        public static string AppSecrect = WebConfigurationManager.AppSettings["wxpay_h5_appsecret"];

        /// <summary>
        /// 公众号 获取Access_Token的Url(需Format  0.AppId 1.Secret)
        /// </summary>
        public const string AccessToken_Url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";


        /// <summary>
        /// 公众号 发送模板消息
        /// </summary>
        public const string TemplateMessage = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}";

        /// <summary>
        /// 公众号 获取Token的Url
        /// </summary>
        public static string WeiXin_AccessTokenUrl { get { return string.Format(AccessToken_Url, AppId, AppSecrect); } }

        /// <summary>
        /// 获取Access_Token
        /// </summary>
        /// <returns></returns>
        public static string GetAccessToken()
        {
            string url = WeiXin_AccessTokenUrl;
            string result = HttpClientHelper.GetResponse(url);
            return result;
        }
    }
}
